﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PMS.Common;
using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.EntityQuery;

public partial class Modules_System_SelfInfo : System.Web.UI.Page
{
    ISys_UserHandler userHandler = new Sys_UserManage();
    ISys_RoleHandler roleHandler = new Sys_RoleManage();
    ISys_OrganizationHandler orgHandler = new Sys_OrganizationManage();
    ISys_PostHandler postHandler = new Sys_PostManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initail();
        }
    }

    private void initail()
    {
        Sys_UserQuery query = userHandler.GetSys_UserQuery(Convert.ToInt32(Session["CurrentUserID"].ToString()));
        if (query != null)
        {
            txtCode.Text = query.Code;
            txtName.Text = query.Name;
            txtStatus.Text = Enums.GetNormalStatusName((Enums.NormalStatus)query.Status);
            string[] roleIDs = query.Roles.Split(new char[] { ',' });
            string roleName = string.Empty;
            if (roleIDs != null && roleIDs.Length > 0)
            {
                for (int i = 0; i < roleIDs.Length; i++)
                {
                    int roleid = 0;
                    int.TryParse(roleIDs[i], out roleid);
                    Sys_RoleQuery rquery = roleHandler.GetSys_RoleQuery(roleid);
                    if (rquery != null)
                    {
                        roleName += rquery.Name + ";";
                    }
                }
            }
            txtRole.Text = roleName.TrimEnd(new char[] { ';' });

            Sys_OrganizationQuery orgQuery = orgHandler.GetSys_OrganizationQuery(query.Org_ID);
            if (orgQuery != null)
                txtOrgID.Text = orgQuery.Name;
            if (query.Org_ID2 != 0)
            {
                orgQuery = orgHandler.GetSys_OrganizationQuery(query.Org_ID2);
                if (orgQuery != null)
                    txtOrgID2.Text = orgQuery.Name;
            }

            Sys_PostQuery postQuery = postHandler.GetSys_PostQuery(query.Post_ID);
            if (postQuery != null)
                txtPostID.Text = postQuery.Name;
            if (query.Post_ID2 != 0)
            {
                postQuery = postHandler.GetSys_PostQuery(query.Post_ID2);
                if (postQuery != null)
                    txtPostID2.Text = postQuery.Name;
            }
        }
    }
}
